package produceconsumer2;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Consumer {

    private LinkedList<String> list = new LinkedList<>();
    private Object lock;
    private Integer count = 0;

    public Consumer(LinkedList<String> list, Object lock) {
        this.list = list;
        this.lock = lock;
    }

    public void consumeProduct() throws InterruptedException {
        while(true)
        synchronized (lock){
            if(!list.isEmpty()){
                String str = list.getFirst();
                list.removeFirst();
                System.err.println(str+" is consuming");
            }else{
                lock.notifyAll();
            }
            Thread.sleep(100);
        }
    }
}
